﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.ComponentModel;
using UnitVariables;
using System.Reflection;

namespace UnitVariables
{
    public abstract class BaseData : INotifyPropertyChanged
    {
        /// <summary>
        /// INotifyPropertyChanged event.
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;
        /// <summary>
        /// This method notifies the interface that a certain method has changed.
        /// </summary>
        /// <param name="info">Name of the property which has changed as a string.</param>
        protected void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }

        /// <summary>
        /// Updates all of the properties.
        /// </summary>
        public void Update()
        {
            Type t = this.GetType();
            PropertyInfo[] pi = t.GetProperties();
            foreach (PropertyInfo prop in pi)
                NotifyPropertyChanged(prop.Name);
        }

        /// <summary>
        /// Gives a console output of all the properties
        /// </summary>
        public void debug()
        {
            Type t = this.GetType();
            PropertyInfo[] pi = t.GetProperties();
            foreach (PropertyInfo prop in pi)
                Console.WriteLine("Prop {0}: {1}", prop.Name, prop.GetValue(this, null));
        }
    }
}
